﻿
namespace Mulala.Cavan.Application.Seedwork
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using System.Linq;
    using Mulala.Cavan.Core.Persistent;
    using Mulala.Cavan.Domain.Seedwork;

    /// <summary>
    ///     Provides similar Entity (of type T) CRUD methods
    ///     as Dao. They must take care about Business rules
    /// </summary>
    /// <typeparam name = "T">Persitent Entity type</typeparam>
    /// <typeparam name = "TID">the type of the ID property</typeparam>
    public interface IWriteAppService<T, in TID> : IAppService
        where T : class, IPersistentObjectWithTypedId<TID>
    {
        /// <summary>
        ///     Basic write operation for inserting. Stores only new entity.
        /// </summary>
        /// <param name = "entity">new transient entity</param>
        /// <returns>stored entity with defined identifier ID - or still transient entity if any error arises</returns>
        BoolGenericResult<T> Add(T entity);

        /// <summary>
        ///     Basic write operation for changing.
        /// </summary>
        /// <param name = "entity">entity which should be updated</param>
        /// <returns>updated entity - or still transient entity if any error arises</returns>
        BoolGenericResult<T> Update(T entity);

        /// <summary>
        ///     Basic write operation for deleting. Definitely removes entity from storage
        /// </summary>
        /// <param name = "entity"></param>
        BoolGenericResult<T> Delete(T entity);

        BoolGenericResult<T> AddOrUpdate(T entity);
    }
}